﻿#include "forward_system.h"

//头文件声明之后，源文件定义一下
QMap<int,QTcpServer*> Forward_System::global_mapPort;

Forward_System::Forward_System(QObject *parent) : QObject(parent)
{
    
}

bool Forward_System::portIsOccupy(const int &port)
{
    
    if(Forward_System::global_mapPort.find(port) != global_mapPort.end())
    {
        return true;
    }
    return false;
}

bool Forward_System::userPort(const int &port, QTcpServer *server)
{
    if(!portIsOccupy(port))
    {
        Forward_System::global_mapPort[port] = server;
        return true;
    }
    return false;
}

void Forward_System::freedPort(const int &port)

{
    QTcpServer* server = Forward_System::global_mapPort[port];
    if(server != nullptr)
    {
        qDebug()<<"释放相应的监听服务";
        server->close();
        server->deleteLater();
    }
    Forward_System::global_mapPort.remove(port);
}
